﻿//Paging
function turnPage(pageIndex) {
    $("#currIndex").val(pageIndex);
    $("#currLinkToSet").val(pageIndex);
    CallServer(pageIndex, 'content');
}

function turnPagePrev() {
    var prevIndex = parseInt($("#currIndex").val());
    var currentIndex = 1;
    if (prevIndex > 1)
        currentIndex = prevIndex - 1;
    $("#currIndex").val(currentIndex);
    $("#currLinkToSet").val(currentIndex);
    CallServer(currentIndex, 'content');
}

function turnPageNext() {
    var prevIndex = parseInt($("#currIndex").val());
    var currentIndex = $("#lastIndex").val();
    if (prevIndex < $("#lastIndex").val())
        currentIndex = prevIndex + 1;
    $("#currIndex").val(currentIndex);
    $("#currLinkToSet").val(currentIndex);
    CallServer(currentIndex, 'content');
}

function turnPageLast() {
    var currentIndex = $("#lastIndex").val();
    $("#currIndex").val(currentIndex);
    $("#currLinkToSet").val(currentIndex);
    CallServer(currentIndex, 'content');
}

function SetCurrentLink(currentIndex, firstBtn, prevBtn, nextBtn, lastBtn, firstBtn1, prevBtn1, nextBtn1, lastBtn1) {
    var lastIndex = $("#lastIndex").val();
    var i;
    for (i = 1; i <= lastIndex; i++) {
        if (i == currentIndex) {
            $("#a" + i).css('text-decoration', 'underline');
            $("#b" + i).css('text-decoration', 'underline');
        }
        else {
            $("#a" + i).css('text-decoration', 'none');
            $("#b" + i).css('text-decoration', 'none');
        }
    }

    var setting = 5;
    var settingHalf = (setting - 1) / 2;
    if (lastIndex > setting) {
        if (currentIndex > 1) {
            prevBtn.show();
            prevBtn1.show();
        }
        else {
            prevBtn.hide();
            prevBtn1.hide();
        }

        if (currentIndex >= settingHalf + 1) {
            firstBtn.show();
            firstBtn1.show();
        }
        else {
            firstBtn.hide();
            firstBtn1.hide();
        }

        if (currentIndex <= lastIndex - 1) {
            nextBtn.show();
            nextBtn1.show();
        }
        else {
            nextBtn.hide();
            nextBtn1.hide();
        }

        if (currentIndex > (lastIndex - settingHalf - 1)) {
            lastBtn.hide();
            lastBtn1.hide();
        }
        else {
            lastBtn.show();
            lastBtn1.show();
        }
    }
    else {
        prevBtn.hide();
        firstBtn.hide();
        nextBtn.hide();
        lastBtn.hide();

        prevBtn1.hide();
        firstBtn1.hide();
        nextBtn1.hide();
        lastBtn1.hide();
    }

    firstBtn.css("text-decoration", "none");
    prevBtn.css("text-decoration", "none");
    firstBtn1.css("text-decoration", "none");
    prevBtn1.css("text-decoration", "none");

    nextBtn.css("text-decoration", "none");
    lastBtn.css("text-decoration", "none");
    nextBtn1.css("text-decoration", "none");
    lastBtn1.css("text-decoration", "none");
}